/*UNRES Add this annotation to the document let it is inaccessible*/
//SQL代理
let $ = require('./tool')
module.exports = async function(config){
  let token = ''
  let user = await this.fetch({
    url:config.login + '/login',
    method:'POST',
    data:{
      userName:config.userName,
      passWord:$.MD5(config.passWord)
    }
  })
  if(user.token) token = user.token
  this.fetch = async (args) => {
    //请求前自定义 request
    if(!/^http/.test(url)) url = config.baseURL + url
    options = options || {}
    let headers = options.headers || {}
    headers['Content-Type'] = headers['Content-Type'] || 'application/json'
    if(token) headers.token = token
    return await (await fetch(url,{
        method:options.method || 'GET',
        headers,
        body:JSON.stringify(options.data)
    })).json()
  }
}